﻿<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>预约单管理</title>
    <#include "/common/link.ftl">
</head>
<body class="hold-transition skin-black sidebar-mini">
<div class="wrapper">
    <#include "/common/navbar.ftl">
    <!--菜单回显-->
    <#assign currentMenu="appointment"/>
    <#include "/common/menu.ftl">
    <div class="content-wrapper">
        <section class="content-header">
            <h1>预约单管理</h1>
        </section>
        <section class="content">
            <div class="box">
                <!--高级查询--->
                <div style="margin: 20px 0px 0px 10px">
                    <form class="form-inline" id="searchForm" action="/appointment/list" method="post">
                        <input type="hidden" name="currentPage" id="currentPage" value="1">
                        <div class="form-group">
                            <label>预约单流水号</label>
                            <input type="text" class="form-control"  placeholder="请输入预约单流水号" name="ano" value="${qo.ano}">
                        </div>
                                <div class="form-group">
                                    <label>预约业务大类</label>
                                    <select class="form-control"  id="categoryId" name="categoryId">
                                        <option value="">请选择业务大类</option>
                                    </select>
                                </div>
                                <div class="form-group">
                                    <label>预约单状态</label>
                                    <select class="form-control" id="status" name="status">
                                        <option value="">全部</option>
                                        <#list values as v>
                                         <option value="${v.getValue()}"
                                           <#if v.getValue() == qo.status>
                                            selected
                                            </#if>
                                         >${v.getName()}</option>
                                        </#list>
                                    </select>
                                </div>
                                <div class="form-group">
                                    <label>门店查询</label>
                                    <select class="form-control"  id="businessId" name="businessId">
                                        <option value="">请选择门店</option>
                                        <#list businesses as business>
                                            <option value="${business.id}"
                                                    <#if business.id == qo.businessId>
                                                        selected
                                                    </#if>
                                            >${business.name}</option>
                                        </#list>
                                    </select>
                                </div>
                                <div class="form-group">
                                    <label>客户名称</label>
                                    <input type="text" class="form-control"  placeholder="请输入客户名称" name="contactName" value="${qo.contactName}">
                                </div>

                                <div class="form-group">
                                    <label>客户手机号</label>
                                    <input type="text" class="form-control"  placeholder="请输入客户手机号" name="contactTel" value="${qo.contactTel}">
                                </div>

                                <br/>
                                <br/>

                        <div class="form-group">
                            <label>预约时间查询：</label>
                            <input placeholder="请输入开始时间" type="text"  name="startAppointmentTime" value="${(qo.startAppointmentTime?string("yyyy-MM-dd HH:mm"))!}" class="form-control input-datetime-noss"   /> -
                            <input placeholder="请输入结束时间" type="text"  name="endAppointmentTime" value="${(qo.endAppointmentTime?string("yyyy-MM-dd HH:mm"))!}" class="form-control input-datetime-noss"   />
                        </div>

                        <button type="submit" class="btn btn-primary"><span class="glyphicon glyphicon-search"></span> 查询</button>

                        <a href="#" class="btn btn-success btn-input">
                            <span class="glyphicon glyphicon-plus"></span> 添加
                        </a>
                    </form>

                </div>
                <div class="box-body table-responsive ">
                <table class="table table-hover table-bordered table-striped">
                    <thead>
                    <tr>
                        <th>序号</th>
                        <th>流水号</th>
                        <th>业务大类</th>
                        <th>预约说明</th>
                        <th>预约时间</th>
                        <th>客户名称</th>
                        <th>联系方式</th>
                        <th>预约门店</th>
                        <th>状态</th>
                        <th>操作</th>
                    </tr>
                    </thead>
                    <tbody>
                    <#list pageInfo.list as p>
                    <tr>
                        <td>${p_index+1}</td>
                        <td>${p.ano}</td>
                        <td>${p.category.title}</td>
                        <td>${p.info}</td>
                        <td>${(p.appointmentTime?string("yyyy-MM-dd hh:mm"))!}</td>
                        <td>${p.contactName}</td>
                        <td>${p.contactTel}</td>
                        <td>${p.business.name}</td>
                        <td>${p.statusName}</td>
                        <td>
                            <a href="#" class="btn btn-info btn-xs btn-input"  data-json='${p.json}'>
                                <span class="glyphicon glyphicon-pencil"></span> 编辑
                            </a>
                            <a class="btn btn-xs btn-primary btn-status"  data-id='${p.id}' data-status='1'>
                                <span class="glyphicon glyphicon-phone-alt"></span> 确认预约</a>
                            <a class="btn btn-xs btn-danger btn-status" data-id='${p.id}' data-status='4'>
                                <span class="glyphicon glyphicon-remove" ></span> 取消预约</a>
                            <a href="#" class="btn btn-success btn-xs btn-consume" data-id='${p.id}' data-ano='${p.ano}'>
                                <span class="glyphicon glyphicon-shopping-cart"></span> 确认到店
                            </a>
                        </td>
                    </tr>
                    </#list>
                    </tbody>
                </table>
                    <!--分页-->
                    <#include "/common/page.ftl">
                </div>

            </div>
        </section>
    </div>
    <#include "/common/footer.ftl">
</div>


<#-- 文件上传模态框 -->
<!--模态框-->
<div class="modal fade" id="editModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <h4 class="modal-title" id="myModalLabel">新增/编辑</h4>
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span>
                </button>
            </div>

            <form id="editForm" action="/appointment/saveOrUpdate" method="post" >
                <div class="modal-body">
                    <input type="hidden" name="id" id="id">
                    <div class="form-group row">
                        <label class="col-sm-3 col-form-label">预约门店：</label>
                        <div class="col-sm-7">
                            <select class="form-control" name="business.id" id="business_id">
                                <option value="">请选择预约门店</option>
                                <#list businesses as business>
                                    <option value="${business.id}">${business.name}</option>
                                </#list>
                            </select>
                        </div>
                    </div>
                    <div class="form-group row">
                        <label class="col-sm-3 col-form-label">预约时间：</label>
                        <div class="col-sm-7">
                            <input type="text"  class="form-control input-datetime-noss" placeholder="请输入预约时间" name="appointmentTime" id="appointmentTime"/>
                        </div>
                    </div>
                    <div class="form-group row">
                        <label class="col-sm-3 col-form-label">业务大类：</label>
                        <div class="col-sm-7">
                            <select class="form-control" name="category.id" id="category">
                                <option value="">请选择业务大类</option>
                            </select>
                        </div>
                    </div>

                    <div class="form-group row">
                        <label class="col-sm-3 col-form-label">联系人：</label>
                        <div class="col-sm-7">
                            <input type="text" class="form-control"
                                   placeholder="请输入联系人" name="contactName" id="contactName">
                        </div>
                    </div>
                    <div class="form-group row">
                        <label class="col-sm-3 col-form-label">联系电话：</label>
                        <div class="col-sm-7">
                            <input type="text" class="form-control"
                                   placeholder="请输入联系电话" name="contactTel" id="contactTel">
                        </div>
                    </div>
                    <div class="form-group row">
                        <label class="col-sm-3 col-form-label">预约说明：</label>
                        <div class="col-sm-7">
                            <textarea type="text" class="form-control"
                                      placeholder="请输入预约说明" name="info" id="info"></textarea>
                        </div>
                    </div>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                    <button type="submit" class="btn btn-primary btn-submit">保存</button>
                </div>
            </form>
        </div>
    </div>
</div>
<script>
    //抽取修改预约单状态的方法
    function changeStatus(id,status){
        $.post('/appointment/changeStatus', {"id": id, "status": status}, function (data) {
            if (data.success){
                Swal.fire({
                    title: '保存成功',
                    icon: 'success',
                    confirmButtonText: 'OK',
                }).then((result) => {
                    if (result.value) {
                        //点击确认按钮后做的事情
                        location.reload();
                    }
                })
            }else {
                Swal.fire({
                    title: data.msg,
                    icon: 'error',
                    confirmButtonText: 'OK',
                }).then((result) => {
                    if (result.value) {
                        //如果登陆成功则跳转员工页面
                        location.reload();
                    }
                })}
        })
    }

    //客户到店按钮
    $('.btn-consume').click(function () {
        let id = $(this).data('id');
        let ano = $(this).data('ano');
        Swal.fire({
            text: "是否到店?",
            icon: 'info',
            showCancelButton: true,
            confirmButtonText: '是',
            cancelButtonText: '否'
        }).then((result) => {
            //已经到店
            if (result.value) {
                //判断是否有消费
                Swal.fire({
                    title: '是否有消费',
                    icon: 'info',
                    showCancelButton: true,
                    confirmButtonText: '有消费',
                    cancelButtonText: '未消费'
                }).then((result) => {
                    if (result.value) {
                        $.post('/consumption/save',{"appointAno":ano},function (data) {
                            if (data.success){
                                //跳转新增界面
                                window.location.href='/consumption/input?id='+data.data;
                            }
                        })
                    }else {
                        //如果没有消费则将预约单改成完结状态
                        changeStatus(id,3);
                        //刷新当前界面
                        location.reload();
                    }
                })
            }else{
                //未到店则将预约单的状态改成废弃
                changeStatus(id,4);
            }
        })
    });


    //发送ajax请求，将查询到的数据拼接到下拉框中
    $.post('/systemDictionaryItem/selectBySn',{sn:"business"},function (data) {
        data.forEach(function (ele) {
            $('#category').append('<option value="'+ele.id+'">'+ele.title+'</option>');
            $('#categoryId').append('<option value="'+ele.id+'">'+ele.title+'</option>');
        });
        $('#categoryId').val(${qo.categoryId});
    })
</script>

<script>
    $('.btn-input').click(function () {
        $('#editForm input').val('');
        $('#editForm select').val('');
        let json = $(this).data('json');
        if (json){
            $('#id').val(json.id);
            $('#business_id').val(json.business.id);
            $('#appointmentTime').val(json.appointmentTime);
            $('#category').val(json.category.id);
            $('#contactName').val(json.contactName);
            $('#contactTel').val(json.contactTel);
            $('#info').val(json.info);
        }
        $('#editModal').modal('show');
    });
    $('#editModal').ajaxForm(function (data) {
        Swal.fire({
            title: '保存成功',
            icon: 'success',
            confirmButtonText: 'OK',
        }).then((result) => {
            if (result.value) {
                //点击确认按钮后做的事情
                location.reload();
            }
        })
    });


    //修改状态
    $('.btn-status').click(function () {
        let id =$(this).data('id');
        let status = $(this).data('status');
        changeStatus(id,status);
    })
</script>
</body>
</html>
